package com.idbk.chargestation.util;

import android.text.Html;
import android.text.Spanned;

import com.idbk.chargestation.AppContext;

/**
 * 检测工具类
 * Created by zhx on 2017/12/8.
 */

public class CheckUtil {

    private static boolean isFirstOpenApplication = true;
    /**
     * 是否希望当前版本显示引导页,建议为大版本更新时才设置为true <p>
     * */
    private static final boolean APPLICATION_BIG_VERSION_UPDATE = false;


    public static boolean isShowGuidePage() {
        // 安装应用后非第一次打开直接返回false
        if (!isFirstOpenApplication) {
            return false;
        }
        isFirstOpenApplication = false;
        int saveVersionCode = AppContext.getInstance().getSaveVersionCode();
        int currentVersionCode = AppContext.getInstance().getApplicationVersionCode();
        // 第一次安装或者是卸载后重新安装显示引导页
        if (saveVersionCode <= 0) {
            AppContext.getInstance().saveVersionCode(currentVersionCode);
            return true;
        }
        // 更新新版本后第一次打开且新版本为大版本时显示引导页
        if (currentVersionCode > saveVersionCode) {
            AppContext.getInstance().saveVersionCode(currentVersionCode);
            if (APPLICATION_BIG_VERSION_UPDATE) {
                return true;
            }
        }
        return false;
    }

    @SuppressWarnings("deprecation")
    public static Spanned textFromHtml(String text) {
        Spanned charSequence;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
            charSequence = Html.fromHtml(text, Html.FROM_HTML_MODE_LEGACY);
        } else {
            charSequence = Html.fromHtml(text);
        }
        return charSequence;
    }
}
